#!/usr/bin/python3

import requests
import sys

f = open(r'ck.txt', 'r')
cookies={}

for line in f.read().split(';'):
    name,value = line.strip().split('=', 1)
    cookies[name] = value
    #print(f'{name} = {value}')

f.close()

#url = 'https://coding.jd.com/api/v4/groups/254900/projects'
#url = 'https://coding.jd.com/api/v4/groups'
#url = 'https://coding.jd.com/api/v4/projects/Vessel_OS%2F{}/members/33979'.format(sys.argv[1])

data_2 = {
 "min_access_level": 50,
}


#res = requests.get(url, cookies=cookies)
#res = requests.get(url, cookies=cookies, data=data_2)
#res = requests.delete(url, cookies=cookies)
#print(res.text)

#sys.exit(0)

data = {
 "new_owner_erp": "sanglipeng1",
}

data2 = {
 "new_owner_erp": "hanxiangyuan",
}

repo_list_path = sys.argv[1]

f = open(repo_list_path, 'r')

count = 0
for repo in f.readlines():
    r = repo.strip()
    #print(f'{r}')
    count = count + 1
    #url = 'https://coding.jd.com/api/v4/projects/Vessel_OS%2F{}/change_owner'.format(r)
    url = 'https://coding.jd.com/api/v4/projects/jd-kernel%2F{}/change_owner'.format(r)
    print(f'handling {count} ...')
    res = requests.put(url, cookies=cookies, data=data)
    print(res.text)



'''
url = 'https://coding.jd.com/api/v4/projects/Vessel_OS%2F{}/members/331'.format(sys.argv[1])
data_2 = {
 "access_level": 50,
}

res = requests.put(url, cookies=cookies, data=data_2)
print(res.text)
'''
